package com.klm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.klm.common.ResultInfo;
import com.klm.model.*;
import com.klm.params.*;
import com.klm.service.TranslateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wq
 */
@Slf4j
@RestController
@RequestMapping("/translate")
public class TranslateController {

    @Autowired
    private TranslateService lsCoreTranslateIF;

    @PostMapping("/content/get")
    public ResultInfo<ComLangModel> getLangContentByFrom(@RequestBody GetLangContentParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getLangContentByFrom(params.getFromTable(),
                params.getFromField(), params.getFromDataId()));
    }

    @PostMapping("/itemKey")
    public ResultInfo<String> getUniqueItemKey(@RequestBody GetUniqueItemKeyParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getUniqueItemKey(params.getFromTable(),
                params.getFromField(), params.getDescription(), params.getOperator()));
    }

    @PostMapping("/fullContent/get")
    public ResultInfo<ComLangModel> getFullContentByItemKey(@RequestBody GetFullContentParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getFullContentByItemKey(params.getItemKey()));
    }

    @PostMapping("/singleContent")
    public ResultInfo<ComLangContentModel> getSingleContentByItemKey(@RequestBody GetSingleContentParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getSingleContentByItemKey(params.getItemKey()));
    }

    @PostMapping("/langContent")
    public ResultInfo<ComLangContentModel> getLangContentByItemKey(@RequestBody GetLangContentByItemKeyParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getLangContentByItemKey(params.getItemKey(), params.getLangCode()));
    }

    @PostMapping("/content/save")
    public ResultInfo<Boolean> saveContentByItemKey(@RequestBody SaveContentParams params) {
        return ResultInfo.build(lsCoreTranslateIF.saveContentByItemKey(params.getItemKey(),
                params.getLangCode(), params.getContent(), params.getOperator()));
    }

    /**
     * 獲取語種列表
     * @return 語種列表
     */
    @PostMapping("/langCode/default")
    public ResultInfo<ComLangCodeModel> getDefaultLangCode() {
        return ResultInfo.build(lsCoreTranslateIF.getDefaultLangCode());
    }

    /**
     * 獲取語種列表
     * @return 語種列表
     */
    @PostMapping("/langCodeList")
    public ResultInfo<List<ComLangCodeModel>> getLangCodeList() {
        return ResultInfo.build(lsCoreTranslateIF.getLangCodeList());
    }

    @PostMapping("/tableFieldList")
    public ResultInfo<Page<ComTableFieldModel>> getFromTableAndFieldList(@RequestBody GetTableFieldListParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getFromTableAndFieldList(params.getPageNum(), params.getPageSize()));
    }

    @PostMapping("/fullContent/save")
    public ResultInfo<Boolean> saveFullContentByItemKey(@RequestBody SaveLangContentModel saveLangContentModel) {
        return ResultInfo.build(lsCoreTranslateIF.saveFullContentByItemKey(saveLangContentModel));
    }

    @PostMapping("/noMasterItems")
    public ResultInfo<Page<AutoLanguageItemModel>> getNoMasterLanguageItemPage(
            @RequestBody GetNoMasterItemsParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getNoMasterLanguageItemPage(params.getPageNum(),
                params.getPageSize(), params.getItemKey(),
                params.getFromTable(), params.getFromField(), params.getMemo()));
    }

    @PostMapping("/items")
    public ResultInfo<Page<AutoLanguageItemModel>> getLanguageItemPage(
            @RequestBody GetLanguageItemsParams params) {
        return ResultInfo.build(lsCoreTranslateIF.getLanguageItemPage(params.getPageNum(),
                params.getPageSize(), params.getItemKey(),
                params.getFromTable(), params.getFromField(), params.getFromDataId(), params.getMemo()));
    }

    @PostMapping("/content/remove")
    public ResultInfo<Boolean> logicDelLanguageContent(@RequestBody DeleteLanguageContentParams params) {
        return ResultInfo.build(lsCoreTranslateIF.logicDelLanguageContent(params.getItemKey(),
                params.getFromDataId(), params.getOperator()));
    }

    @PostMapping("/content/del/before")
    public ResultInfo<Integer> delLanguageContentBeforeDate(@RequestBody DeleteBeforeDateParams params) {
        return ResultInfo.build(lsCoreTranslateIF.delLanguageContentBeforeDate(params.getBeforeDate(),
                params.getOperator()));
    }

    @PostMapping("/refreshRedis")
    public ResultInfo<Boolean> refreshRedis() {
        return ResultInfo.build(lsCoreTranslateIF.refreshRedis());
    }

    @PostMapping("/update/bid")
    public ResultInfo<Boolean> updateBizId(@RequestParam String itemKey,
                                                    @RequestParam String bizId) {
        // TODO 待补充
        return ResultInfo.build(true);
    }
}
